<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>新开卡或卡充值提成模板管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		fieldset{
			display:inline-block;width:100%;
		}
		.ui-field-contain fieldset div.ui-input-text{
			float:left;
			width:60%;
		}
		#cardList{
			float:right;width:78%;height:300px;border:1px solid #cccccc;display:block;
			overflow: auto;border-radius:0;
		}
		#cardList li a{
			border-color:#f3f3f3;
			background:#fff;
			color:#000;
		}
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#name").focus();
			$("#inputForm").validate({
				rules:{
	                "fixed_money": "ifMoney",
	                "bonus_rate": {
	                 	"range":[0,100] 
	                 }
	            },
				submitHandler: function(form){
					var ids = "";
					var lists = $("#cardList li");
					for(var i =0; i < lists.length; i++) {
						var item = lists[i];
						ids += item.id + ",";
					}
					if(ids == ''){
						showTip("没有选择会员卡！");
						return;
				 	}
					$("#cardIds").val(ids);
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			var bonus_type = ${storeBonusSettingTemplateCard.bonus_type};
			if(bonus_type == 0) {
				$("#type_radio_2").css('display', 'none');
	     		$("#type_radio_1").css('display', 'block');
			} else {
				$("#type_radio_1").css('display', 'none');
	     		$("#type_radio_2").css('display', 'block');
			}
     		$('input:radio').click(function(){
             	var id =  $(this).val();
             	if(id == 0) {
             		$("#bonus_rate").val('0');
             		$("#fixed_money").val('0.0');
             		$("#type_radio_2").css('display', 'none');
             		$("#type_radio_1").css('display', 'block');
             		
             	} else {
             		$("#bonus_rate").val('0');
             		$("#fixed_money").val('0.0');
             		$("#type_radio_1").css('display', 'none');
             		$("#type_radio_2").css('display', 'block');
             	}
            });
		});
		function addCard(){
			var type = $("#card_template_type").val();
			var url = '${ctx}/employee/storeBonusSettingTemplateCard/cardTemplateData?type=' + type;
			var extIds = "";
			var lists = $("#cardList li");
			for(var i =0; i < lists.length; i++) {
				var item = lists[i];
				extIds += item.id + ",";
			}
			global.addMultSelectList(url, "选择会员卡", extIds, "cardList");
		}
	</script>
</head>
<body>
	<form:form id="inputForm" class="form-input" modelAttribute="storeBonusSettingTemplateCard" action="${ctx}/employee/storeBonusSettingTemplateCard/addNew" method="post">
		<form:hidden path="id"/>
		<input id="cardIds" name="cardIds" type="hidden"/>
		<div class="icon-buttons">
			<a data-role="button" data-inline="true" data-icon="back" data-iconpos="notext"  href="${ctx}/employee/storeBonusSettingTemplateCard/">返回</a>
			<input type="submit" value="保 存" data-icon="check" data-iconpos="notext"  data-inline="true"/>
		</div>
		<tags:message content="${message}"/>
		<div data-role="fieldcontain">
			<label for="card_template_type">会员卡类别:</label>
			<form:select path="card_template_type" data-native-menu="false" items="${fns:getDictMap('card_type')}"></form:select>
		</div>
		<div data-role="fieldcontain">
			<label for="categoryList">会员卡名称:</label>
			<input type="button" value="选择会员卡" data-inline="true" data-icon="plus" onclick="addCard()">
			<ul id="cardList" data-role="listview" data-inset="true"  data-split-icon="delete" data-split-theme="a">
			</ul>
		</div>
		<div data-role="fieldcontain">
			<fieldset data-role="controlgroup" data-type="horizontal" data-inline="true">
				<legend>提成方式:</legend>
				<form:radiobuttons path="bonus_type" items="${fns:getDictMap('bonus_type')}"/>
			</fieldset>
		</div>
		<div data-role="fieldcontain" id="type_radio_1">
   			<label for="bonus_rate">提成比例(%):</label>
    		<input type="number" id="bonus_rate" value="${fns:changeDisCount(storeBonusSettingTemplateCard.bonus_rate)}" name="bonus_rate" class="required digits"/>
		</div>
		<div data-role="fieldcontain" id="type_radio_2">
			<label for="fixed_money">提成金额(元):</label>
			<form:input path="fixed_money" htmlEscape="false" class="required"/>
		</div>
	</form:form>
</body>
</html>
